CC = gcc
CFLAGS = -Wall -Wextra -std=c99
LIBS = -lmysqlclient
LIBDIR = RELEASE
INCDIR = Include

# 库文件
LIBS_FILES = $(LIBDIR)/libdata_io.a $(LIBDIR)/libstudent.a $(LIBDIR)/libcourse.a

# 目标文件 - 只保留数据库和控制台版本
TARGET_DATABASE = $(LIBDIR)/student_course_db.out
TARGET_CONSOLE = $(LIBDIR)/student_course_console.out
	
.PHONY: all clean database console

all: database console

database: $(TARGET_DATABASE)

console: $(TARGET_CONSOLE)

$(TARGET_DATABASE): Main.c $(LIBS_FILES)
	$(CC) $(CFLAGS) -I$(INCDIR) $< -L$(LIBDIR) -ldata_io -lstudent -lcourse $(LIBS) -o $@ -DDATABASE_INPUT

$(TARGET_CONSOLE): Main.c $(LIBS_FILES)
	$(CC) $(CFLAGS) -I$(INCDIR) $< -L$(LIBDIR) -ldata_io -lstudent -lcourse $(LIBS) -o $@ -DCONSOLE_INPUT

$(LIBS_FILES):
	$(MAKE) -C ModuleA
	$(MAKE) -C ModuleB
	$(MAKE) -C ModuleC

clean:
	$(MAKE) -C ModuleA clean
	$(MAKE) -C ModuleB clean
	$(MAKE) -C ModuleC clean
	rm -f $(TARGET_DATABASE) $(TARGET_CONSOLE)

install:
	sudo apt-get install libmysqlclient-dev

.PHONY: run-console run-database
run-console: console
	./$(TARGET_CONSOLE)

run-database: database
	./$(TARGET_DATABASE)